#ifndef OPTICALFLOWSEGMENTER_H
#define OPTICALFLOWSEGMENTER_H

#include <stdlib.h>
#include <time.h>

#include <QWidget>
#include <QIcon>
#include <QPushButton>
#include <QGridLayout>
#include <QDebug>
#include <QColor>
#include <QSet>
#include <QGLPixelBuffer>

#include <vcg/complex/trimesh/update/color.h>

#include "core/gui/opengl/scene/scene.h"
#include "core/gui/opengl/glwindow.h"

typedef std::pair<int, int> ImageCoordinate;
typedef std::set< ImageCoordinate > PixelCluster;
	

class Color : public QColor
{

public:
	Color() {}

	bool operator < (const Color& b) const {
		if ( red() == b.red() ) {
			if ( green() == b.green() ) {
				return blue() < b.blue();
			}
			return green() < b.green();
		}
		return red() < b.red();
	}
};

class OpticalFlowSegmenter : public QWidget
{
	Q_OBJECT

public:
	OpticalFlowSegmenter(std::vector<CGMesh*>& meshlist, int active, GLCamera& camera, GLWindow& window_par, QWidget* parent = 0);
	~OpticalFlowSegmenter();

private:

	//members
	std::vector<CGMesh*>& meshlist;		//reference to mesh list
	int active;							//index of active mesh
	GLCamera& camera;					//reference to GL camera
	GLWindow& window;					//reference to GL window

	//images
	std::vector < QImage* > shots;		//images


	//methods
	vcg::Point2f getBarycenter( PixelCluster );
        bool isAdjacent( PixelCluster pc, ImageCoordinate query );

public slots:
	//methods
	void colorizeMeshFaces();
	void takeSnapshot();
	void computeFlow();

signals:
	void updateView();
	void hideMesh(int);
	void showMesh(int);
	
};

#endif // OPTICALFLOWSEGMENTER_H
